package(default_visibility = ["//visibility:public"])

load(
    "@rules_haskell//haskell:defs.bzl",
    "haskell_binary",
    "haskell_library",
)
load(
    "@rules_haskell//haskell:cabal.bzl",
    "haskell_cabal_binary",
    "haskell_cabal_library",
)
load(
    "//:build/common.bzl",
    "EXECUTABLE_FLAGS",
    "GHC_FLAGS",
)

haskell_library(
    name = "semantic-ast",
    srcs = glob(["src/**/*.hs"]),
    compiler_flags = GHC_FLAGS + ["-XOverloadedStrings"],
    deps = [
        "//:base",
        "//:bytestring",
        "//:containers",
        "//:filepath",
        "//:template-haskell",
        "//:text",
        "//semantic-source",
        "@stackage//:Glob",
        "@stackage//:aeson",
        "@stackage//:aeson-pretty",
        "@stackage//:attoparsec",
        "@stackage//:bazel-runfiles",
        "@stackage//:directory",
        "@stackage//:fused-effects",
        "@stackage//:hedgehog",
        "@stackage//:optparse-applicative",
        "@stackage//:pathtype",
        "@stackage//:pretty-simple",
        "@stackage//:tasty",
        "@stackage//:tasty-hedgehog",
        "@stackage//:tasty-hunit",
        "@stackage//:tree-sitter",
        "@stackage//:tree-sitter-python",
        "@stackage//:unordered-containers",
    ],
)

all_ts_deps = ["@tree-sitter-{name}".format(name = name) for name in [
    "go",
    "java",
    "json",
    "php",
    "python",
    "ql",
    "ruby",
    "rust",
    "tsx",
    "typescript",
]]

all_file_deps = ["@tree-sitter-{name}//:src/node-types.json".format(name = name) for name in [
    "go",
    "java",
    "json",
    "php",
    "python",
    "ql",
    "ruby",
    "rust",
    "tsx",
    "typescript",
]]

haskell_binary(
    name = "generate-ast",
    srcs = glob(["app/**/*.hs"]),
    compiler_flags = GHC_FLAGS + EXECUTABLE_FLAGS + ["-XStrictData"],
    data = all_file_deps,
    deps = [
        ":semantic-ast",
        "//:base",
        "//:filepath",
        "//:process",
        "//:template-haskell",
        "//:text",
        "//semantic-source",
        "@stackage//:bazel-runfiles",
        "@stackage//:directory",
        "@stackage//:generic-lens",
        "@stackage//:lens",
        "@stackage//:neat-interpolation",
        "@stackage//:optparse-generic",
        "@stackage//:tree-sitter",
    ] + all_ts_deps,
)
